package net.bungaeting.client.android.activity;

import java.util.Map;

import net.bungaeting.client.android.request.RequestObserver;
import net.bungaeting.client.android.task.BackgroundService;
import net.bungaeting.client.android.utils.JsonUtil;
import net.bungaeting.client.android.utils.ServiceConst;
import net.bungaeting.client.android.utils.ServiceUtil;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TestActivity extends Activity {
	BackgroundService backgroundService = new BackgroundService();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.test);
		
		init();
		
		Button buttonTest1 = (Button)findViewById(R.id.buttonTest1);
		if (buttonTest1 != null){
			buttonTest1.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					test1();
				}
			});
		}
		
	}
	
	public void init(){
		ServiceUtil.getClientId(this);
		backgroundService.startWorkerThread();
		String serviceId = ServiceConst.SERVICE_ID_CREATE_MEETING;
		
		backgroundService.addObserver(ServiceUtil.makeRequestId(serviceId), serviceId, new RequestObserver(RequestObserver.THREAD_TYPE.UI_THREAD){
			@Override
			public void update(String requestId, String returnCode, String returnMsg, Object params) {
				// TODO Auto-generated method stub
				Log.d("TEST", "Observer update complate()");
				Log.d("TEST", "requestId " + requestId);
				Log.d("TEST", "returnCode " + returnCode);
				Log.d("TEST", "returnMsg " + returnMsg);
				Log.d("TEST", "params " + params);
			}
	
		});
	}
	
	protected void test1(){
		Map<String, Object> map = JsonUtil.toMap("{'organizer': {'name': '박영규', 'phoneNo': '15555215554'}, 'groupName':'인턴모임', 'participants':[{'name': '박영규', 'phoneNo': '15555215554'}, {'name': '최현철', 'phoneNo': '01041115632'}, {'name': '박상아', 'phoneNo': '01065052435'}], 'region':{'x' : '126.65544', 'y' : '33.397', 'tags' : ['술집', '음식점', '베니건스']}, 'appointmentTime':	'2011-06-18 19:30:00', 'message':'만나요22!'}");
//		Log.d("TEST", map.toString());
//		Log.d("TEST", JsonUtil.toJSonString(map));

		String serviceId = ServiceConst.SERVICE_ID_CREATE_MEETING;
		
		final TestActivity activity = this;
		backgroundService.requestAsync(serviceId, ServiceUtil.makeRequestId(serviceId), map, new RequestObserver(RequestObserver.THREAD_TYPE.UI_THREAD){
			@Override
			public void update(String requestId, String returnCode, String returnMsg, Object params) {
				// TODO Auto-generated method stub
				Log.d("TEST", "update complate()");
				Log.d("TEST", "requestId " + requestId);
				Log.d("TEST", "returnCode " + returnCode);
				Log.d("TEST", "returnMsg " + returnMsg);
				Log.d("TEST", "params " + params);
			}
		});

	}
}
